import 'package:city_corner/commons/global-var.dart';
import 'package:city_corner/commons/my-raised-btn.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/**
 * 筛选栏列表内容
 */
class OptList extends StatefulWidget {
  final List opts;
  final dynamic onPressed;
  OptList(
      {this.opts = const [
        {'label': '无', 'value': ''}
      ],
      this.onPressed = Null});

  @override
  _OptListState createState() => _OptListState();
}

class _OptListState extends State<OptList> {
  int activeIndex = 0;

  @override
  Widget build(BuildContext context) {
    BtnColor btnColor = new BtnColor();

    return Container(
        width: mediaSize(context).width / 2,
        child: MediaQuery.removePadding(
          context: context,
          removeTop: true,
          child: ListView.separated(
            itemCount: widget.opts.length,
            itemBuilder: (context, index) {
              return Container(
                  child: MyRaisedBtn(
                text: widget.opts[index]['label'],
                textColor:
                    activeIndex == index ? btnColor.orange : btnColor.grey,
                onPressed: () {
                  setState(() {
                    activeIndex = index;
                  });
                  if (widget.onPressed != Null) {
                    widget.onPressed(index);
                  }
                },
              ));
            },
            separatorBuilder: (context, index) {
              return Divider(height: 10, indent: 75, color: Color(0xFFDDDDDD));
            },
          ),
        ));
  }
}
